package myapp.Chat;

import staticClass.XmppConnection;
import myapp.EnumAndConstans.Constants;
import myapp.googlemap.R;
import myapp.services.ChatServiceHelper;
import android.app.Dialog;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class NewUserDialog extends Dialog implements android.view.View.OnClickListener{
	
	private XmppClient xmppClient;
	
	public NewUserDialog(XmppClient client) {
		super(client);
		// TODO Auto-generated constructor stub
		this.xmppClient = client;
	}
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();	
		
		Initialize();
	}
	
	private void Initialize(){
		setContentView(R.layout.chat_your_name_dialog);
		getWindow().setFlags(Constants.WINDOW_FLAG_FOR_DIALOG, Constants.WINDOW_MASKS_FOR_DIALOG);
		setTitle("You are new User? Enter your name here!");
		
		SetClickListeners();
	}

	private void SetClickListeners() {
		// TODO Auto-generated method stub
		Button btnConfirm = (Button) findViewById(R.id.chat_your_name_confirm);
		btnConfirm.setOnClickListener(this);
	}
	
	public void onClick(View v){
		ChatServiceHelper helper = new ChatServiceHelper();
		EditText widget = (EditText) this.findViewById(R.id.chat_your_name_textBox);
		String userName = widget.getText().toString();
		helper.addNewUser(XmppConnection.userEmail, userName, XmppConnection.hashPwd);
		Log.i("NewUserDialog", "[onClick]: New user created!");
		xmppClient.newUserCreatedCallBack();
		dismiss();
	}
}
